﻿using System;
using System.Text;
using NIIT.SaoBacDau.Aupi.HospitalManagement.Entities;
using NIIT.SaoBacDau.Aupi.HospitalManagement.DataAccess;
using System.Text.RegularExpressions;

namespace NIIT.SaoBacDau.Aupi.HospitalManagement.BusinessLogic
{
    public class BL_HR_Login
    {
        public static HR_Employee EmployeeName;
        public static HR_Login objlogin;
        public static HM_Cookie Cookie;
        public static HM_Account Account;
        public static HM_LoginError Login(HR_Login Ac,HM_Cookie cookie,HM_Account account)
        {
            Cookie = cookie;
            Account = account;
            Regex r = new Regex(@"\A{6}\w{0,30}\w\z");
            if (r.IsMatch(Ac.UserName) == false)
                return HM_LoginError.FormatUserName;
            else if (string.IsNullOrEmpty(Ac.Password))
                return HM_LoginError.PasswordIsEmpty;
            else if (r.IsMatch(Ac.Password) == false)
                return HM_LoginError.FormatPassword;
            else if (DAO_HR_Login.Login(Ac) == null)
                return HM_LoginError.NotAccount;
            else
                return HM_LoginError.NoError;
        }

        public static HR_Employee WellComeEmployee(HR_Login Ac)
        {
            HR_Employee obj = DAO_HR_Login.ProfileEmployee(Ac);
            objlogin = DAO_HR_Login.Login(Ac);
            EmployeeName = obj;
            return obj;
        }
        public static HM_Role HR_Role(HR_Login hr_Log)
        {
            if (hr_Log.Role == 1)
                return HM_Role.ReceptionAndManagementPatient;
            else if (hr_Log.Role == 2)
                return HM_Role.OpdAndEPrescription;
            else if (hr_Log.Role == 3)
                return HM_Role.ManagementHumanResources;
            else if (hr_Log.Role == 4)
                return HM_Role.ManagementDrug;
            else if (hr_Log.Role == 5)
                return HM_Role.ManagementEquipment;
            else if (hr_Log.Role == 6)
                return HM_Role.ManagementDispatch;
            else if (hr_Log.Role == 7)
                return HM_Role.ManagementLibrary;
            else
                return HM_Role.Administrator;
        }
    }
}
